package com.kgo.log.logtools.file;

import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.core.io.file.FileReader;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Dealfile {
    private static final Logger log = LoggerFactory.getLogger(Dealfile.class);
    private static Cache<String,String> fifoCache = CacheUtil.newFIFOCache(100);
    public static String getCache(String path){
        String content = fifoCache.get(path);
        return content;
    }
    public static void addCache(String path,String content){
       fifoCache.put(path,content);
    }
    public static String getNewStr(String path){
        FileReader fileReader = new FileReader(path);

        String allStr = fileReader.readString();
        log.debug("全部数据"+allStr);
        String oldStr = getCache(path);
        log.debug("缓存数据"+allStr);
        String resuleStr = StringUtils.isBlank(oldStr) ? allStr:StringUtils.replace(allStr,oldStr,"");
        log.debug("最新数据：{}",resuleStr );
        addCache(path,allStr);
        return resuleStr;
    }
    public static String getAllStr(String path){
        FileReader fileReader = new FileReader(path);
        String allStr = fileReader.readString();

        return allStr;
    }
}
